import requests
import json
albummid='003dAEX43IElBh'
# 替换为你的真实接口地址
url = f"http://localhost:3300/album/songs?albummid={albummid}"

response = requests.get(url)
data = response.json()

# 提取专辑数据
album_data = data.get("data", {})
album_mid = album_data.get("albummid", "")
song_list = album_data.get("list", [])

# 获取专辑名称
album_name = song_list[0].get("album", {}).get("name", "未知专辑") if song_list else "未知专辑"

# 构建歌曲列表（包含 singers 列表）
songs = []
for song in song_list:
    song_name = song.get("name", "")
    song_mid = song.get("mid", "")

    singers = song.get("singer", [])
    singer_objs = [
        {
            "singer_id": s.get("mid", ""),
            "singer_name": s.get("name", "")
        }
        for s in singers
    ]

    songs.append({
        "song_name": song_name,
        "song_mid": song_mid,
        "singers": singer_objs
    })

# 构建最终结构
result = {
    "album_name": album_name,
    "album_mid": album_mid,
    "songs": songs
}

# 输出 JSON
print(json.dumps(result, indent=2, ensure_ascii=False))